package test;

import com.suxin.App;
import com.suxin.domain.Blue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

/**
 * @author Tang
 * @classname MainTest1
 * @description [  ]
 * @date 2021/5/8 21:44
 */
@SpringBootTest(classes = {App.class})
@RunWith(SpringRunner.class)
public class MainTest1 {

    @Resource
    GenericApplicationContext applicationContext;

    @Resource
    App app;

    @Test
    public void test() {
        ObjectProvider<Blue> beanProvider = applicationContext.getBeanProvider(Blue.class);
        System.out.println(beanProvider.getIfAvailable());
    }

    @Test
    public void test02(){
        AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(Blue.class);
        AnnotationBeanNameGenerator nameGenerator = new AnnotationBeanNameGenerator();
        System.out.println(nameGenerator.generateBeanName(beanDefinition, applicationContext));
    }

}